package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-21 9:59
 */
@Configuration
public class OrderCancelMqConfig {

	@Bean
	public Queue delayQueue() {
		return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
	}

	@Bean
	public CustomExchange delayExchange() {
		HashMap<String, Object> map = new HashMap<>();
		map.put("x-delayed-type", "direct");
		return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL, "x-delayed-message", true, false, map);
	}

	@Bean
	public Binding delayBinding() {
		return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
	}

}
